package com.rover022.flixelgame.ui.npcshop
{
	import com.rover022.flixelgame.manager.EventHelper;
	import com.rover022.flixelgame.manager.ItemManager;
	import com.rover022.flixelgame.manager.PlayerManager;
	import com.rover022.flixelgame.ui.BaseUI;
	import com.rover022.flixelgame.ui.equipupgrade.GeneralityGridUI;
	import com.rover022.flixelgame.vo.ItemVo;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import ghostcat.ui.PopupManager;

	public class GroceryShopUI extends BaseUI
	{
		public var itemContainer:Sprite;

		public function GroceryShopUI()
		{
			super();
			itemContainer = new Sprite();
		}

		public function showAllItems():void
		{
			var items:Array = PlayerManager.getInstance().getGroceryGoods();
			for (var i:int = 0; i < items.length; i++)
			{
				var itemvo:ItemVo = ItemManager.getInstance().getItemFromConfig(items[i]);
				var grid:GeneralityGridUI = ItemManager.getInstance().makeGeneralityGrid(items[i]);
				EventHelper.addEventListener(grid,MouseEvent.CLICK,girdClick);
				itemContainer.addChild(grid);
			}
		}
		
		private function girdClick(e:MouseEvent):void
		{
			var panel:ProductGridUI = new ProductGridUI();
			PopupManager.instance.showPopup(panel);
		}
		
		public function removeAllGoods():void{
			itemContainer.removeChildren();
		}
		
		public function refreshGoods(e:MouseEvent=null):void{
			removeAllGoods();
			showAllItems();
		}
		
	}
}